<template lang="jade">
div
  h-loader-full(url='loader')
    m-title(icon="add",name='添加音频')
    table.single
      mf-row(name='标题：'): input(type='text',v-model='add.name')
      mf-row(name='简述：'): input(type='text',v-model='add.intro')
      mf-row(name='上传音频：', id="form_area")
        form(enctype="multipart/form-data", id="form")
          input(type='file', name="file", id="file")
      mf-row(name='音频链接：'): input(type='text',v-model='add.url')
      mf-row(name='音频图片：'): mf-upload(uploadid='img', amount='1',project='xiongan',category='logo',@upload_data='text',:data='add.img')
      mf-row(name='创建时间：'): input(type='datetime-local',v-model='add.time')
      mf-row(name='')
        button(@click='edit') 确认修改
</template>

<script>
export default {
	data () {
		return {
      loader:{
        list:'audio/detail/manager/' + this.$query.get('id')
      },
      list:{},
      add:{
        name:'',
        intro:'',
        img:[],
        time:'',
        url:"",
        id:this.$query.get('id')
      },
		}
	},
	mounted () {

      $(()=>{
        $("#form_area").find("em").hide();
        $("#file").change(()=>{
          var formData = new FormData($("#form"));
          formData.append("file", document.getElementById("file").files[0]);      
          if($("#file").val() == ""){
            alert("没有上传任何文件");
            return;
          }
          $.ajax({
              url: 'http://hxq.test.sgboke.com/uploadaudio.php',
              type:"post",
              data:formData,
              processData:false,
              contentType:false,
              success:(res) => {
                this.add.url = res;
              },
              error:(err)=>{
                console.log(err);
              },
          })
        })
      })

	},
	methods: {
    text(data){
			this.add.img = data
		},
    loadAfter(res){
      this.list = res.list[0]
      this.add = this.list
      this.add.img = this.add.img.split('|')
      this.add.time = new Date(this.add.time * 1000).format("yyyy-MM-ddThh:mm")
    },
    edit(){
      this.$ajax.put('audio/edit/manager',this.add,(res)=>{
        this.$msg.success('编辑成功')
        setTimeout("window.location.href='audio_list.html'",1500)
      },(err)=>{
        this.$msg.error(err)
      })
    }
	}
}
</script>

<style lang="less">
@import "../../../plugin/style/mixin.less";

</style>